/**
 * 
 */
package com.et114.modules.org.dao;

import com.et114.components.acegi.Constants;
import com.et114.core.common.AppContext;
import com.et114.core.dao.impl.BaseDAOImpl;
import com.et114.core.exception.CheckException;
import com.et114.modules.org.vo.FuncComponentVo;

import java.util.List;

//import org.apache.commons.beanutils.PropertyUtils;
/**
 * @author guanhw
 */
public class FunctionCompDAO extends BaseDAOImpl {
	
	
	public FuncComponentVo getFuncComp( Long funcElementId ) throws CheckException { 
		FuncComponentVo vo = new FuncComponentVo();
		vo.setFuncElementId ( funcElementId ) ; 
		return ( FuncComponentVo ) load( vo , "getFunctionComps" ) ;
	}
	
	public List getFuncComps( FuncComponentVo vo  ) throws CheckException { 
		return queryList(  vo , "getFunctionComps" ) ;
	}
	
	public List getFunctionCompsWithCountRel( FuncComponentVo vo  ) throws CheckException {  
		return queryList(  vo , "getFunctionCompsWithCountRel" ) ;
	}
	
	
	public List getFuncComps(  ) throws CheckException { 
		return queryList(  new FuncComponentVo() , "getFunctionComps" ) ;
	}
	
	
	public int countFuncComps( FuncComponentVo vo  ) throws CheckException { 
		return getCount( vo , "countFuncComps" ).intValue ( ) ;
	} 
	
	public List getRolesByFuncCompId (  Long id  ) throws CheckException { 
		return queryList( id  , "getRolesByFunctionCompId" ) ;
	}
	 
	/*
	 * roleType >
	 */
	public List getRolesByFuncComp ( FuncComponentVo vo  ) throws CheckException {
		return queryList( vo  , "getRolesByFunctionComp" ) ;
	}
	
	
	public Long countgetRolesByFunctionComp( FuncComponentVo vo  ) throws CheckException { 
		return getCount ( vo , "countgetRolesByFunctionComp" );
	}
	
	
	public List getRolesByFuncCompNPage ( FuncComponentVo vo  ) throws CheckException {
		return queryList( vo  , "getRolesByFunctionCompNPage" ) ;
	}

	/*
	 * roleType =
	 */
	public List getRolesByFuncCompo ( FuncComponentVo vo  ) throws CheckException {
		return queryList( vo  , "getRolesByFunctionComp2" ) ;
	}
	
	public List getTitlesByFuncCompId( Long id  ) throws CheckException { 
		return queryList( id , "getTitlesByFunctionCompId" ) ;
	}
	
	public int countgetTitlesByFunctionCompId( Long id  ) throws CheckException { 
		return getCount ( id , "countgetTitlesByFunctionCompId" ).intValue ( );
	}
	
	
	public List getUsersByFuncCompId( Long id  ) throws CheckException { 
		return queryList( id  , "getUsersByFunctionCompId" ) ;
	}
	
	public void saveLogFuncComp( FuncComponentVo log )  throws CheckException { 
		insert( log , "insertLogFuncCom"  ) ;
	}
	
	public void saveFuncComp( FuncComponentVo vo  ) throws CheckException {  
		insert( vo , "insertFunctionComp"  ) ;
		if ( AppContext.isHasLog (  ) ) {	
			vo.setOperUser ( vo.getCrtUser ( )) ;
			vo.setOperType ( Constants.LOG_OPER_NEW ) ; 
			saveLogFuncComp( vo ) ; 
		}
	}
	
	public void updateFuncComp( FuncComponentVo vo  ) throws CheckException { 
		update(  vo , "updateFunctionComp" ) ;
		if ( AppContext.isHasLog (  ) ) {		
			vo.setOperUser ( vo.getUpdtUser ( ) ) ;
			vo.setOperType ( Constants.LOG_OPER_UPDATE ) ; 
			saveLogFuncComp( vo ) ; 
		}
	}
	
	/**
	 * 
	 * @param funcElementId
	 * @throws CheckException
	 */
	public void deleteFuncCompById( Long funcElementId , Long operUser ) throws CheckException {
		if ( AppContext.isHasLog (  ) ) {		
			FuncComponentVo log = getFuncComp( funcElementId ) ; 
			log.setOperUser ( operUser ) ;
			log.setOperType ( Constants.LOG_OPER_REMOVE ) ; 
			saveLogFuncComp( log ) ; 
		}
		delete( funcElementId  , "deleteFunctionCompById" ) ;
	} 
	
	//@AUTHOR ZXY
	public Long countFunctionComp( FuncComponentVo vo  ) throws CheckException { 
		return getCount ( vo , "countFunctionComp" );
	}
	
	/*
	public List getFunctionClsByUserAllPrincipals( Long userId ) throws CheckException {  
		return queryList( userId , "getFunctionClsByUserAllPrincipals" ) ;
	}*/
	
}
